package com.zjt.vlcmedia;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private VlcVideoView vlcVideoView;
    private TextView tvPlay;
    private TextView tvPause;
    private final static String VIDEO_URL = "rtmp://220.161.87.62:1935/live/0";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        vlcVideoView = findViewById(R.id.video_view);

        tvPlay = findViewById(R.id.tv_play);
        tvPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!vlcVideoView.isPlaying()) {
                    vlcVideoView.play();
                }
            }
        });

        tvPause = findViewById(R.id.tv_pause);
        tvPause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vlcVideoView.pause();
            }
        });

        initVideo();
    }

    private void initVideo() {
        vlcVideoView.setOrientationListener(new VlcVideoView.OrientationListener() {
            @Override
            public void onOrientation(int orientation) {

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        vlcVideoView.setVideoUrl(VIDEO_URL);
        vlcVideoView.play();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (vlcVideoView != null) {
            vlcVideoView.onStop();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (vlcVideoView != null) {
            vlcVideoView.onDestroy();
        }
    }

    @Override
    public void onBackPressed() {
        if (vlcVideoView != null) {
            vlcVideoView.onBackPressed();
        }
    }
}
